﻿$(function () {

    //--------------------------------排序----------------------------------
    $('#grid_itemSN').click(function () {
        sorting($(this), 'itemSN', 'itemSN', 'itemSNDESC')
    });

    $('#grid_addtime').click(function () {
        sorting($(this), 'addtime', 'addtime', 'addtimeDESC')
    });

    switch (sortorder) {
        case "itemSN":
            $('#grid_itemSN').attr('value', 'itemSN');
            break;
        case "itemSNDESC":
            $('#grid_itemSN').attr('value', 'itemSNDESC');
            break;
        case "addtime":
            $('#grid_addtime').attr('value', 'addtime');
            break;
        case "addtimeDESC":
            $('#grid_addtime').attr('value', 'addtimeDESC');
            break;
    }
    //------------------------------------------------------------------------

    //-----------------------------搜索---------------------------------------
    $('#grid_search').click(function () {
        var itemname = $('#itemname_search').val();
        var itemSN = $('#itemSN_search').val();
        var addtime = $('#addtime_search').val();
        var linkaddr = $('#linkaddr_search').val();
        searchparam = 'itemname=' + itemname + '&itemSN=' + itemSN + '&addtime=' + addtime + '&linkaddr=' + linkaddr;
        window.location = generateUrl();
    });

    $('#clear_search').click(function () {
        searchparam = '';
        window.location = generateUrl();
    });

});

//对上次排序进行反序 
function sorting(element,defaultval, val1, val2) {
    var val = element.attr('value');
    if (val == '') {
        element.attr('value', defaultval);
    } else {
        if (val == val1) element.attr('value', val2);
        else element.attr('value', val1);
    }
    sortparam = 'sortorder=' + element.attr('value');
    window.location = generateUrl();
}
